<template>
    <view class="content ml20 mr20">
        <view class="dis_sb mt60 mb40 ml20 mr20">
            <view class="line26">
                <view class="f34 clo-navyBlue">审核管理</view>
                <view class="clo-gray f24">审核的内容包含原始数据和修改后数据</view>
            </view>
            <image src="/static/pic5.png" mode="widthFix" class="pic"></image>
        </view>
        <view class="dis_sb ">
            <view class="left rad15 bgfff" v-if="Object.keys(fields).length && Object.keys(after_data).length">
                <view class="bgblue clo-fff f34 line18 tac">修改数据</view>
                <template v-for="(item, key) in after_data">
                    <template v-if="fields[key] && ['id','create_time'].indexOf(key) == -1">
                        <view v-if="fields[key].type=='select' || fields[key].type=='radio'"><text class="clo-blue pr10">•</text>{{fields[key].title}}：{{ fields[key].extra[item] || '无' }}</view>
                        <view v-else><text class="clo-blue pr10">•</text>{{fields[key].title}}：{{item}}</view>
                    </template>
                </template>
            </view>
            <view class="right rad15 bgeee" v-if="Object.keys(fields).length && Object.keys(before_data).length">
                <view class="bgaaa clo-fff f34 line18 tac">原数据</view>
                <template v-for="(item, key) in before_data">
                    <template v-if="fields[key] && ['id','create_time'].indexOf(key) == -1">
                    <view v-if="fields[key].type=='select' || fields[key].type=='radio'"><text class="clo-999 pr10">•</text>{{ fields[key].title }}：{{ fields[key].extra[item] || '无' }}</view>
                    <view v-else><text class="clo-999 pr10">•</text>{{ fields[key].title }}：{{item}}</view>
                     </template>
                </template>
            </view>
        </view>
        <div class="pb20">
            <button class="bbg mt60" @click="audit(1)" :disabled="post_lock">审核通过</button>
            <button class="butredkong" @click="audit(2)" :disabled="post_lock">审核不通过</button>
        </div>
    </view>
</template>


<script setup>
import { ref, reactive, toRefs, onMounted, computed, onUnmounted, getCurrentInstance } from 'vue'
import useMescroll from '@/uni_modules/mescroll-uni/hooks/useMescroll.js';
import { onLoad, onPageScroll, onReachBottom } from '@dcloudio/uni-app';
import { redirect } from '@/utils/common'
import { getAuditInfo, changeAuditStatus } from '@/utils/api'
const { proxy } = getCurrentInstance();
proxy.$checkUserType();
const after_data = ref({})
const before_data = ref({})
const fields = ref({})
const audit_id = ref(0);
onLoad((e)=>{
    console.log('e')
    if (!e.id){
        proxy.$showToast('参数错误');
        setTimeout(() => {
            uni.navigateBack({
                delta: 1
            })

        }, 2000)
        return false;
    }
    audit_id.value = e.id
    getAuditInfo({id:e.id}).then((res)=>{
        console.log('res',res.data)
        after_data.value = res.data.info.after_data
        before_data.value = res.data.info.before_data
        fields.value = res.data.fields
    })
})


const post_lock = ref(false);
const audit = (status)=>{
    if (post_lock.value) {
        return false;
    }
    let content = '确认要审核通过吗？'
    if (status  == 2){
        content = '确认要审核不通过吗？'
    }
    uni.showModal({
        title: '提示',
        content: content,
        showCancel: true, //是否显示取消按钮
        cancelText: '取消',
        confirmText: '确认',
        success(res2) {
            if (res2.confirm) {
                post_lock.value = true;
                // 1通过 2不通过
                changeAuditStatus({ id: audit_id.value,status}).then((res)=>{
                    setTimeout(() => {
                        uni.$emit('refreshAudit', true);
                        post_lock.value = false;
                        uni.navigateBack({
                            delta: 1
                        })
                    }, 1500)
                }).catch(err => {
                    setTimeout(() => {
                        post_lock.value = false;
                    }, 1000)
                })
            } else if (res2.cancel) {
            }
            return false;
        }
    })
}
</script>

<style>
	.pic {width: 180rpx;}
	.tit {padding-left: 20rpx;}
	.tit::after {top: 12%; left: 0;}
	.main {height: 70vh; overflow-y: auto;}
	.bbg {width: 25%;}
	.left ,.right{width: 50%; box-sizing: 0 0 10rpx #eee; overflow: hidden;}
	.left view ,.right view {padding-left: 15rpx; line-height: 2; color: #333; font-size: 28rpx;}
	.right {transform: scale(0.98);}
	.right view {color: #888;}
	button {width: 60%!important; margin: 30rpx 20%; line-height: 2.2;}
</style>
